package com.tanhua.dubbo.listener;

import com.tanhua.dubbo.mapper.UserInfoMapper;
import com.tanhua.dubbo.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class FreezeCancelExpirtionListener extends KeyExpirationEventMessageListener {

    @Autowired
    private UserInfoMapper userInfoMapper;

    public FreezeCancelExpirtionListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    @Override
    public void onMessage(Message message, byte[] pattern) {
        String keyExpird = message.toString();
        if (keyExpird.contains("FREEZE_USER_")){
            String userId = keyExpird.replace("FREEZE_USER_", "");
            userInfoMapper.updateUserStatusById(Long.valueOf(userId),"1");
        }
    }
}
